home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994…tember: Reference Library / Dev.CD Sep 94.toast / Periodicals / develop / develop Issue 15 / develop 15 code / 3D Interface / Demo3D / UDemo3D.cp < prev    next >
Encoding:
Text File  |  1993-06-02  |  9.7 KB  |  330 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        Demo3D.cp
  3.  
  4.     Contains:    3D drawing demo program
  5.  
  6.     Written by:    Jamie Osborne
  7.  
  8.     Copyright:    © 1992-1993 by Apple Computer, Inc.
  9.  
  10. */
  11.  
  12. #include "UDemo3D.h"
  13.  
  14. #ifndef __TOOLUTILS__
  15. #include <ToolUtils.h>
  16. #endif
  17.  
  18. #ifndef __UFAILURE__
  19. #include <UFailure.h>
  20. #endif
  21.  
  22. #ifndef __UVIEWSERVER__
  23. #include <UViewServer.h>
  24. #endif
  25.  
  26.  
  27. #ifndef __UMACAPPUTILITIES__
  28. #include <UMacAppUtilities.h>
  29. #endif
  30.  
  31. #ifndef __MENUS__
  32. #include <Menus.h>
  33. #endif
  34.  
  35. #ifndef __UWINDOW__
  36. #include <UWindow.h>
  37. #endif
  38.  
  39.  
  40. #ifndef __RESOURCES__
  41. #include <Resources.h>
  42. #endif
  43.  
  44. #ifndef __STDLIB__
  45. #include <StdLib.h>
  46. #endif
  47.  
  48. #ifndef __UCONTROL__
  49. #include <UControl.h>
  50. #endif
  51.  
  52. #include "U3DDrawing.h"
  53.  
  54. //----------------------------------------------------------------------------------------
  55. // Constants
  56. const short c3DDrawingWind = 1001;
  57. const short c3DDrawingProcWind = 1002;
  58.  
  59. const short kModalDialog = 1010;
  60. const short kBadWindow = 1011;
  61.  
  62. const short kStrings     = 2000;
  63.  
  64. //========================================================================================
  65. // CLASS TTestApplication
  66. //========================================================================================
  67.  
  68.  
  69. //----------------------------------------------------------------------------------------
  70. // TTestApplication::ITestApplication: 
  71. //----------------------------------------------------------------------------------------
  72. #pragma segment AInit
  73.  
  74. pascal void TTestApplication::ITestApplication()
  75.  
  76. {
  77.     IApplication(kFileType, kSignature);
  78.  
  79.     macroDontDeadStrip(TDemoWindow);
  80.     
  81.     fLaunchWithNewDocument = FALSE;        // Suppress the creation of a new document at launch
  82.     
  83.     this->DoMenuCommand(c3DDrawingWind);        // Show the View window
  84.  
  85. } // TTestApplication::ITestApplication 
  86.  
  87. //----------------------------------------------------------------------------------------
  88. // TTestApplication::DoMakeDocument: 
  89. //----------------------------------------------------------------------------------------
  90. #pragma segment AOpen
  91.  
  92. pascal TDocument* TTestApplication::DoMakeDocument(CommandNumber    /*itsCommandNumber*/,
  93.                                                    TFile*           /*itsFile*/ )// override 
  94.  
  95. {
  96.     return NULL;
  97. } // TTestApplication::DoMakeDocument 
  98.  
  99.  
  100. //----------------------------------------------------------------------------------------
  101. // TTestApplication::DoMenuCommand: 
  102. //----------------------------------------------------------------------------------------
  103. #pragma segment ASelCommand
  104.  
  105. pascal void TTestApplication::DoMenuCommand(CommandNumber aCommandNumber)// override 
  106.  
  107.  
  108. {
  109.     switch (aCommandNumber)
  110.     {
  111.         case c3DDrawingWind:
  112.             MakeDrawingWind();
  113.             break;
  114.         case c3DDrawingProcWind:
  115.             MakeDrawingProcWind();
  116.             break;
  117.         default:
  118.             inherited::DoMenuCommand(aCommandNumber);
  119.             break;
  120.     }
  121. } // TTestApplication::DoMenuCommand 
  122.  
  123.  
  124. //----------------------------------------------------------------------------------------
  125. // TTestApplication::DoSetupMenus: 
  126. //----------------------------------------------------------------------------------------
  127. #pragma segment ARes
  128.  
  129. pascal void TTestApplication::DoSetupMenus()// override 
  130.  
  131. {
  132.     inherited::DoSetupMenus();
  133.  
  134.     Enable(c3DDrawingWind, TRUE);
  135.     Enable(c3DDrawingProcWind, TRUE);
  136.  
  137. } // TTestApplication::DoSetupMenus 
  138.  
  139.  
  140. //----------------------------------------------------------------------------------------
  141. // TTestApplication::MakeDrawingWind: 
  142. //----------------------------------------------------------------------------------------
  143. pascal void TTestApplication::MakeDrawingWind()
  144.  
  145. {
  146.     TWindow *        aWindow;
  147.  
  148.  
  149.     FailNIL(aWindow = gViewServer->NewTemplateWindow(c3DDrawingWind, NULL));
  150.     aWindow->Open();
  151. } // TTestApplication::MakeTemplateViews 
  152.  
  153.  
  154. //----------------------------------------------------------------------------------------
  155. // TTestApplication::MakeDrawingProcWind: 
  156. //----------------------------------------------------------------------------------------
  157. #pragma segment ASelCommand
  158.  
  159. pascal void TTestApplication::MakeDrawingProcWind()
  160.  
  161. {
  162.     TWindow *aWindow;
  163.     VPoint    itsLocation, itsSize;
  164.     
  165.     FailNIL(aWindow = gViewServer->NewTemplateWindow(c3DDrawingProcWind, NULL));
  166.  
  167.     TStaticText *aStaticText = new TStaticText;
  168.     itsLocation = VPoint(15, 13);
  169.     itsSize = VPoint(362, 16);
  170.     aStaticText->IStaticText(aWindow, itsLocation, itsSize, sizeVariable, sizeVariable, kStrings, 1);
  171.     
  172.     TStaticText *aStaticText2 = new TStaticText;
  173.     itsLocation = VPoint(278, 188);
  174.     itsSize = VPoint(188, 48);
  175.     aStaticText2->IStaticText(aWindow, itsLocation, itsSize, sizeVariable, sizeVariable, kStrings, 2);
  176.  
  177.     TStaticText *aStaticText3 = new TStaticText;
  178.     itsLocation = VPoint(269, 53);
  179.     itsSize = VPoint(116, 16);
  180.     aStaticText3->IStaticText(aWindow, itsLocation, itsSize, sizeVariable, sizeVariable, kStrings, 3);
  181.  
  182.     TCluster *aCluster = new TCluster;
  183.     itsLocation = VPoint(266, 120);
  184.     itsSize = VPoint(199, 53);
  185.     aCluster->ICluster(aWindow, itsLocation, itsSize, sizeVariable, sizeVariable, kNoResource, 0);
  186.     aCluster->SetLabel("A Cluster!", kRedraw);
  187.  
  188.     itsSize = VPoint(78, 18);
  189.     T3DRadio *aRadio1 = new T3DRadio;
  190.     itsLocation = VPoint(10, 13);
  191.     aRadio1->I3DRadio(aCluster, itsLocation, itsSize, sizeVariable, sizeVariable, "Radio 1", TRUE);
  192.  
  193.     T3DRadio *aRadio2 = new T3DRadio;
  194.     itsLocation = VPoint(10, 31);
  195.     aRadio2->I3DRadio(aCluster, itsLocation, itsSize, sizeVariable, sizeVariable, "Radio 2" , FALSE);
  196.  
  197.     T3DRadio *aRadio3 = new T3DRadio;
  198.     itsLocation = VPoint(107, 13);
  199.     aRadio3->I3DRadio(aCluster, itsLocation, itsSize, sizeVariable, sizeVariable, "Disabled", FALSE);
  200.     
  201.     T3DRadio *aRadio4 = new T3DRadio;
  202.     itsLocation = VPoint(107, 31);
  203.     aRadio4->I3DRadio(aCluster, itsLocation, itsSize, sizeVariable, sizeVariable, "Disabled", FALSE);
  204.     aRadio4->DimState(TRUE, FALSE);
  205.     aRadio4->SetEnable(FALSE);
  206.  
  207.     T3DCheckBox *aCheckBox = new T3DCheckBox;
  208.     itsLocation = VPoint(26, 203);
  209.     itsSize = VPoint(154, 18);
  210.     aCheckBox->I3DCheckBox(aWindow, itsLocation, itsSize, sizeVariable, sizeVariable, "Enabled Check Box", FALSE);
  211.  
  212.     T3DCheckBox *aCheckBox2 = new T3DCheckBox;
  213.     itsLocation = VPoint(26, 218);
  214.     itsSize = VPoint(154, 28);
  215.     aCheckBox2->I3DCheckBox(aWindow, itsLocation, itsSize, sizeVariable, sizeVariable, "Disabled Check Box", FALSE);
  216.     aCheckBox2->DimState(TRUE, FALSE);
  217.     aCheckBox2->SetEnable(FALSE);
  218.     
  219.     T3DButton *aButton = new T3DButton;
  220.     itsLocation = VPoint(374, 244);
  221.     itsSize = VPoint(82, 20);
  222.     aButton->I3DButton(aWindow, itsLocation, itsSize, sizeVariable, sizeVariable, "Show Me");
  223.     aButton->fIdentifier = 'BDBn';
  224.     aButton->SetHilitedTextColor(CRGBColor(65535, 9109, 2210));
  225.  
  226.     T3DButton *aButton2 = new T3DButton;
  227.     itsLocation = VPoint(280, 244);
  228.     itsSize = VPoint(82, 20);
  229.     aButton2->I3DButton(aWindow, itsLocation, itsSize, sizeVariable, sizeVariable, "Disabled");
  230.     aButton2->DimState(TRUE, FALSE);
  231.     aButton2->SetEnable(FALSE);
  232.     
  233.     T3DIconButton *anIcon = new T3DIconButton;
  234.     itsLocation = VPoint(36, 76);
  235.     itsSize = VPoint(26, 26);
  236.     anIcon->I3DIconButton(aWindow,itsLocation, itsSize, sizeFixed, sizeFixed, 16, 1002, kButtonMode, FALSE);
  237.     anIcon->fIdentifier = 'IBn1';
  238.  
  239.     T3DIconButton *anIcon2 = new T3DIconButton;
  240.     itsLocation = VPoint(36, 121);
  241.     itsSize = VPoint(26, 26);
  242.     anIcon2->I3DIconButton(aWindow,itsLocation, itsSize, sizeFixed, sizeFixed, 16, 1002, kButtonMode, FALSE);
  243.     anIcon2->DimState(TRUE, FALSE);
  244.     anIcon2->SetEnable(FALSE);
  245.  
  246. /*       Took this out because of a compiler bug that couldn't handle this many register vars
  247.     TView *aView = new TView;
  248.     itsLocation = VPoint(246, 54);
  249.     itsSize = VPoint(2, 210);
  250.     aView->IView(NULL,aWindow,itsLocation, itsSize, sizeFixed, sizeFixed);
  251.  
  252.     T3DLineLeftAdorner *aLineAdorner = new T3DLineLeftAdorner;
  253.     aLineAdorner->I3DLineLeftAdorner(TRUE);
  254.     aView->AddAdorner(aLineAdorner, kAdornLast, TRUE);
  255. */
  256.  
  257.     TEditText *anEditText = new TEditText;
  258.     itsLocation = VPoint(269, 69);
  259.     itsSize = VPoint(199, 22);
  260.     anEditText->IEditText(aWindow, itsLocation, itsSize, 255);
  261.     anEditText->SetText("Edit Text", kDontRedraw);
  262.     anEditText->DeleteAdornerByID(kFrameAdorner, TRUE);        // We make our own frame
  263.     
  264.     TWhiteBackgroundAdorner    *back = new TWhiteBackgroundAdorner;
  265.     back->IWhiteBackgroundAdorner(TRUE);
  266.     
  267.     T3DFrameAdorner    *frame = new T3DFrameAdorner;
  268.     frame->I3DFrameAdorner(TRUE);
  269.     
  270.     anEditText->AddAdorner(back, kAdornFirst, TRUE);
  271.     anEditText->AddAdorner(frame, kAdornLast, TRUE);
  272.     
  273.     TControl *aControl = new TControl;
  274.     itsLocation = VPoint(93, 68);
  275.     itsSize = VPoint(134, 90);
  276.     aControl->IControl(aWindow,itsLocation, itsSize, sizeFixed, sizeFixed);
  277.     
  278.     TWhiteBackgroundAdorner    *back2 = new TWhiteBackgroundAdorner;
  279.     back2->IWhiteBackgroundAdorner(TRUE);
  280.     
  281.     T3DFrameAdorner    *frame2 = new T3DFrameAdorner;
  282.     frame2->I3DFrameAdorner(TRUE);
  283.     aControl->AddAdorner(back2, kAdornFirst, TRUE);
  284.     aControl->AddAdorner(frame2, kAdornLast, TRUE);
  285.  
  286.     TextStyle style;
  287.     GetPortTextStyle(style);
  288.     itsLocation = VPoint(2,2);
  289.     itsSize = VPoint(115, 86);
  290.     TScroller *scroller = new TScroller;
  291.     scroller->IScroller(aControl, itsLocation, itsSize, sizeRelSuperView, sizeRelSuperView,
  292.                                 VPoint(86, 86), FALSE, TRUE);
  293.                                 
  294.     TTextListView *aTextListView = new TTextListView;
  295.     aTextListView->ITextListView(NULL, scroller, itsLocation, itsSize, sizeSuperView,
  296.                                          sizeSuperView, 2, 16, 0, FALSE, FALSE, 2, 2, TRUE, style);
  297.  
  298.  
  299.     aWindow->Open();
  300. } // TTestApplication::MakeProcedureViews 
  301.  
  302.  
  303. pascal void TDemoWindow::DoEvent(EventNumber eventNumber,
  304.                                      TEventHandler* source,
  305.                                      TEvent* event)
  306. {
  307.     switch(eventNumber)
  308.     {
  309.         case mButtonHit:
  310.             if (source == this->FindSubView('BDBn'))
  311.             {
  312.                 TWindow *aWindow;
  313.                 FailNIL(aWindow = gViewServer->NewTemplateWindow(kBadWindow, NULL));
  314.                 aWindow->Open();
  315.             }
  316.             break;
  317.         case mIconButtonHit:
  318.             if (source == this->FindSubView('IBn1'))
  319.             {
  320.                 TWindow *aWindow;
  321.                 FailNIL(aWindow = gViewServer->NewTemplateWindow(kModalDialog, NULL));
  322.                 IDType dismisser = aWindow->PoseModally();
  323.                 if (dismisser == 'ok  ')
  324.                     aWindow->CloseAndFree();
  325.             }
  326.             break;
  327.         default:
  328.             inherited::DoEvent(eventNumber, source, event);
  329.     }
  330. }